var stuIdToken = null;
var loginToken = null;
(function($, owner) {

	owner.get_user_info = function() {
		owner.get_local_state();
		var url = USER_API + "/getUserInfo.do";
		console.log(loginToken);
		var parms = {
			loginToken: loginToken
		};
		return requestService.httpPost(url, parms);
	}

	owner.user_login = function(stuId, password) {
		var url = USER_API + "/login.do";
		var parms = {
			stuId: stuId,
			password: password
		};
		return requestService.httpPost(url, parms);
	}

	owner.login_out = function() {
		var url = USER_API + "/logout.do";
		var parms = {
			loginToken: loginToken
		};
		return requestService.httpGet(url, parms);
	}
	owner.update_password = function(oldPassword, newPassword) {
		owner.get_local_state();
		var url = USER_API + "/updatePwd.do";
		var parms = {
			loginToken: loginToken,
			oldPwd: oldPassword,
			newPwd: newPassword
		};
		return requestService.httpPost(url, parms);
	}

	owner.update_user_info = function(user) {
		owner.get_local_state();
		var url = USER_API + '/update.do?loginToken=' + loginToken;
		console.log(stuIdToken);
		user.loginToken = loginToken;
		return requestService.httpPost(url, user);
	}

	owner.user_register = function(stuId, password, email) {
		var url = USER_API + '/register.do';
		var user = new Object;
		user.stuId = stuId;
		user.password = password;
		user.email = email;
		console.log(JSON.stringify(user));
		return requestService.httpPost(url, user);
	}

	owner.send_email = function(email) {
		var url = USER_API + '/sendMail.do';
		var parms = {
			toMail: email
		};
		console.log(JSON.stringify(parms));
		return requestService.httpGet(url, parms);
	}
	owner.reset_password = function(toMail, vCode, pwd) {
		var url = USER_API + '/resetPwd.do';
		var parms = {
			toMail: toMail,
			vCode: vCode,
			pwd: pwd
		};
		return requestService.httpGet(url, parms);
	}

	owner.get_local_state = function() {
		var state = JSON.parse(localStorage.getItem('$state'));
		if(state != null) {
			loginToken = state.loginToken;
		}
	}
}(mui, window.userService = {}));